package com.pcl.ocr.ui

import android.content.Context
import android.content.Intent
import android.os.Handler
import android.os.Looper
import android.os.Message

/**
 *@packageName com.pcl.ocr.ui
 *@author kzcai
 *@date 2022/2/10
 */
object LPRUtils {

    var SEND_CODE = 1

    fun openScan(context: Context,needApply:Boolean,listener:((code:String)->Unit)){
        onScanResultListener = listener
        val intent = Intent(context,LPRActivity::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        intent.putExtra("needApply",needApply)
        context.startActivity(intent)
    }

    private var onScanResultListener:((code:String)->Unit)?=null

    private val handler = object :Handler(Looper.myLooper()!!){
        override fun handleMessage(msg: Message) {
            super.handleMessage(msg)
            if (msg.what == SEND_CODE){
                val code = msg.obj as String
                onScanResultListener?.invoke(code)
            }
        }
    }


    fun sendCode(code:String){
        val msg = Message()
        msg.what = SEND_CODE
        msg.obj = code
        handler.sendMessage(msg)
    }


}